package com.qijian.maindata.domain.vo;

import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.qijian.common.annotation.Excel;
import com.qijian.common.utils.ObjectUtils;
import com.qijian.maindata.domain.BomDetail;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 * BOM明细对象
 *
 * @author qijian
 * @date 2021-09-01
 */

@EqualsAndHashCode(callSuper = true)
@Data
@ToString
public class BomDetailVo extends BomDetail {

    /**
     * 物料名称
     */
    @Excel(name = "物料编号", sort = 2)
    @ApiModelProperty(value = "物料编号")
    private String itemCode;

    /**
     * 物料名称
     */
    @Excel(name = "名称", sort = 7)
    @ApiModelProperty(value = "物料名称")
    private String itemName;

    @ApiModelProperty(value = "物料分类")
    private String itemClassify;

    @Excel(name = "规格", sort = 9)
    @ApiModelProperty(value = "物料规格")
    private String itemSpec;

    @ApiModelProperty(value = "物料单位")
    private String itemUnits;

    @ApiModelProperty(value = "属性类别")
    private String oraCombo;

    @Excel(name = "件号", sort = 8)
    @ApiModelProperty(value = "件号")
    private String partNo;

    @Excel(name = "图号", sort = 6)
    @ApiModelProperty(value = "图号")
    private String drawingNo;

    @Excel(name = "单重", sort = 12)
    private BigDecimal itemWeight;

    @Excel(name = "总重", sort = 13)
    private BigDecimal totalWeight;

    private String itemAttr;
    @JsonSerialize(using = ToStringSerializer.class)
    private Long processId;
    private String processCode;
    private String processName;
    @JsonSerialize(using= ToStringSerializer.class)
    private Long pItemId;
    @JsonSerialize(using= ToStringSerializer.class)
    private Long demandId;
    private String pItemCode;
    private String pItemName;
    private String remark;
    //使用物料分类
    private String pItemClassify;
    /**
     * 数控件图片
     */
    private String url;

    /***
     * 数控件dwg文件
     */
    private String dwgUrl;

    public BigDecimal getTotalWeight() {
        if (ObjectUtils.isNotNull(itemWeight)) {
            return itemWeight.multiply(getTotalQuantity());
        }
        return BigDecimal.ZERO;
    }

    public boolean getHasChildren() {
        return getSubCount() != null && getSubCount() > 0;
    }

    private List<LineProcessVo> processList;

    @Excel(name = "编制人", sort = 14)
    @JsonIgnore
    @TableField(exist = false)
    private String createByExcel;

    @Excel(name = "编制日期", sort = 15, dateFormat = "yyyy/MM/dd HH:mm")
    @JsonIgnore
    @TableField(exist = false)
    private Date createTimeExcel;

    @Excel(name = "工序", sort = 16)
    @JsonIgnore
    @TableField(exist = false)
    private String processNames;

    private String processTypeName;

    @Excel(name = "物料代码", sort = 3)
    @JsonIgnore
    @TableField(exist = false)
    private String itemCodeExcel;

    @JsonIgnore
    @TableField(exist = false)
    private LocalDateTime startTime;
    @JsonIgnore
    @TableField(exist = false)
    private LocalDateTime endTime;


    public String getCreateByExcel() {
        return this.getCreateBy();
    }

    public Date getCreateTimeExcel() {
        return this.getCreateTime();
    }

    public String getItemCodeExcel() {
        return String.format("%s.%s(%s)", this.getItemName(), this.getDrawingNo(), this.getPartNo());
    }

}
